<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@ page import="client.*" %>
<%@ page import="pojo.Message" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'message.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
  <script type="text/javascript">
  	function getdata()//页面刷新,每隔3秒刷新一次
  	{
  		var timeoutid=setTimeout("window.location.reload()",3000);
  	}
  </script>
  </head>
  
  <body onload="getdata();">
    <% 
 	   String msgString="";
       String username=(String)session.getAttribute("username");  
      // System.out.println("user "+username+" get ms");
       ChatClient cc=new ChatClient(); 
       Vector<Message> userms=cc.getUserMessage(username); 
     
       if(userms!=null)
       {
       		for(int i=0;i<userms.size();i++)
       		{
       			Message ms=userms.get(i);
       			String from=ms.getFrom_name();
       			String to=ms.getTo_name();
       			String message=ms.getMs();
       			int flag=ms.getVisiable();
       			
       			if(flag==0)
       			msgString =msgString+"<div><font color=#888888>[私人聊天]</font><font color=green>"+from
       			           +"</font>对<font color=green>"+to
       			           +"</font></span>说："+message
       			           +"</div>";
       			else
       	       msgString =msgString+"<div><font color=green>"+from
       			           +"</font>对<font color=green>"+to
       			           +"</font></span>说："+message
       			           +"</div>";
       		}
       	//	System.out.println("Msg String:" + msgString);
       }	
 %>
 
 <script type="text/javascript">
 ////这个script用来将信息显示在showmessage页面中
  parent.document.getElementById("loadContent").innerHTML="<%=msgString%>";
  //alert("loadContent");
//  parent.location.hash="position";
 </script>
  </body>
</html>
